package com.neusoft.dibuy.lib.cl;

import java.util.Collection;
import java.util.Iterator;

public class MyCollection {
    public static void main(String[] args) {
        Collection<Student> students = new java.util.ArrayList<>();
        students.add(new Student());
        students.add(new Student());
        students.add(new Student());
        Iterator<Student> iterator = students.iterator();
//        iterator.hasNext(); 是否还有违背当前迭代器迭代的元素
//        iterator.next(); 迭代下一个元素
//        迭代器不保证任何迭代顺序；
        while (iterator.hasNext())
        {
            Student s = iterator.next();
            System.out.println(s);
        }



//        ES6
//        Java  ,JavaScript
//        students.forEach( x   -> System.out.println(x)   );
        /**
         * 1、在java中，没有函数类型，所以任何一个函数都不能看做普通实参传达给另一个方法的形参；
         * 2、如果一个函数的形参是接口类型，而且，接口中只有一个方法，那么对象可以省略，方法名也可以省略d
         *
         */
//        students.forEach(
//          student  ->
//                System.out.println(student)
//
//        );
//        students.forEach( x   -> System.out.println(x)   );
//        students.forEach(System.out::println);

    }
    public static void main1(String[] args) {
        Collection<Student> students = new java.util.ArrayList<>();
        students.add(new Student());
        students.add(new Student());
        students.add(new Student());
        Student s1 =  new Student();
        s1.setSno( 2) ;
        System.out.println(students.contains(s1));

    }
}
class  Student extends  Object  implements  Comparable {
   private  static  int index  =0;
    private  int age;
   private  int  sno;

    @Override
    public boolean equals(Object obj) {
        Student s = (Student) obj;
        return this.sno == s.sno;
    }

    public Student()
   {
       this.sno = ++index ;
   }

    public int getSno() {
        return sno;
    }

    public void setSno(int sno) {
        this.sno = sno;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", sno=" + sno +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        return 0;
    }
}